package com.example.administrator.yuejian_2.fragment;


import android.os.Bundle;
<<<<<<< HEAD
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
=======
import android.support.v4.app.Fragment;
>>>>>>> b079ae49aea3652b48f9c84201c89333c2f216f2
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.example.administrator.yuejian_2.R;
<<<<<<< HEAD
import com.example.administrator.yuejian_2.adapter.CoListAdapter;
import com.example.administrator.yuejian_2.bean.ContestListBean;
import com.example.administrator.yuejian_2.interservice.Const;
import com.example.administrator.yuejian_2.interservice.ContestService;

import java.util.List;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;
=======
>>>>>>> b079ae49aea3652b48f9c84201c89333c2f216f2

/**
 * A simple {@link Fragment} subclass.
 */
public class ContestFragment extends Fragment {
<<<<<<< HEAD
    private RecyclerView recyclerView;
    private CoListAdapter adapter;
=======
>>>>>>> b079ae49aea3652b48f9c84201c89333c2f216f2


    public ContestFragment() {
        // Required empty public constructor
    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        return inflater.inflate(R.layout.fragment_contest, container, false);
    }

<<<<<<< HEAD
    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        recyclerView = view.findViewById(R.id.contest_recyclerView);
        Retrofit retrofit = new Retrofit.Builder()
                .baseUrl(Const.BASE_URL)
                .addConverterFactory(GsonConverterFactory.create())
                .build();
        ContestService service = retrofit.create(ContestService.class);
        Call<List<ContestListBean>> call = service.contestlist();
        call.enqueue(new Callback<List<ContestListBean>>() {
            @Override
            public void onResponse(Call<List<ContestListBean>> call, Response<List<ContestListBean>> response) {
                if (getActivity() == null)
                    return;
                adapter = new CoListAdapter(getActivity(),response.body());
                LinearLayoutManager layoutManager = new LinearLayoutManager(getActivity());
                layoutManager.setOrientation(LinearLayoutManager.VERTICAL);
                recyclerView.setLayoutManager(layoutManager);
                recyclerView.setAdapter(adapter);
                recyclerView.setItemAnimator(new DefaultItemAnimator());
            }

            @Override
            public void onFailure(Call<List<ContestListBean>> call, Throwable t) {

            }
        });
    }
=======
>>>>>>> b079ae49aea3652b48f9c84201c89333c2f216f2
}
